package ij3d.utils;
import ij.*;
import java.io.*;
import java.lang.Process;

/**
 *  Interface avec le shell (lancement de commandes)
 *
 *@author     thomas
 *@created    4 septembre 2003
 */
public class Shell {

	/**
	 *  Lancement de commandes
	 *
	 *@param  cmd      La commande
	 *@param  verbose  Description of the Parameter
	 */
	public void LanceCommande(String cmd, boolean verbose) {
		Process p;
		try {
			System.out.println(cmd);
			p = Runtime.getRuntime().exec(cmd);
			// Print command output onto standard output
			InputStream is = p.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			String str;
			while ((str = br.readLine()) != null) {
				if (verbose) {
					System.out.println(str);
				}
			}
			is.close();

			// Wait for the process to complete.
			int status = -1;
			try {
				status = p.waitFor();
			} catch (InterruptedException e) {
				System.out.println(e);
			}
		} catch (java.io.IOException e) {
			System.out.println("erreur " + e);
		}
	}


	/**
	 *  Description of the Method
	 *
	 *@param  cmd  Description of the Parameter
	 */
	public void LanceCommande(String cmd) {
		LanceCommande(cmd, true);
	}
}

